extends Node2D

@onready var board = $Board
@onready var score_label = $UI/ScoreLabel

var score = 0
var game_over = false

func _ready():
	# 初始化游戏
	board.start_new_game()
	board.connect("score_updated", self._on_score_updated)
	board.connect("game_over", self._on_game_over)

func _on_score_updated(new_score):
	score = new_score
	score_label.text = "分数: %d" % score

func _on_game_over():
	game_over = true
	$UI/GameOverScreen.visible = true
	$UI/GameOverScreen/ScoreLabel.text = "最终分数: %d" % score
	$UI/GameOverScreen/NewGameButton.grab_focus()

func _on_new_game_pressed():
	$UI/GameOverScreen.visible = false
	game_over = false
	score = 0
	score_label.text = "分数: 0"
	board.start_new_game()
